package hushi.controller;

import hushi.entity.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.management.Agent;
import hushi.entity.User;

/**
 *
 */
@org.springframework.stereotype.Controller
//@RequestMapping("user")
public class Controller {
    //老方法使用静态代码可以实现
    static String username;
    static {
        username="zhangsan";
    }

    //springmvc使用@ModelAttribute注释实现
    String name;
    @ModelAttribute
    public String userinfo(){
        name="SuxJ";
        return name;
    }
    @ModelAttribute
    public User userinfo3(){
        User user = new User();
        user.setName("TShuang");
        user.setTel("17677777777");
        return user;
    }
    @ModelAttribute
    public User userinfo2(){
        User user = new User();
        user.setName("TShuang");
        user.setTel("17666666666");
        return user;
    }
    @ModelAttribute
    public User userinfo4(){
        User user = new User();
        user.setName("TShuang");
        user.setTel("17688888888");
        return user;
    }

    @ModelAttribute
    public User userinfo5(){
        User user1 = new User();
        user1.setName("TShuang");
        user1.setTel("17699999999");//
        return user1;
    }
    @RequestMapping("search")
    public ModelAndView doPathVariable(User user,User user1){
        System.out.println(username);//zhangsan
        System.out.println(name);//SuxJ
        System.out.println(user);//User{name='TShuang', tel='17666666666', email='null', userage=0}
        System.out.println(user1);//User{name='TShuang', tel='17699999999', email='null', userage=0} 多个user对象只读取了最后一个user对象
        return new ModelAndView("/search.jsp");
    }
}
